package ch;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

public class Copy
{
    public static void main(String[] args) throws IOException
    {
        String root = "E:/work";
        String dest = "C:/Users/Administrator.WIN7U-20130708F/Desktop/test";

        String changeLog = "/orgdeaf/WebContent/pages/front/navi.jsp;/orgdeaf/WebContent/pages/phonepackage;/orgdeaf/WebContent/pages/phonepackage/css;/orgdeaf/WebContent/pages/phonepackage/css/css.css;/orgdeaf/WebContent/pages/phonepackage/images;/orgdeaf/WebContent/pages/phonepackage/images/bbg.jpg;/orgdeaf/WebContent/pages/phonepackage/images/bg.jpg;/orgdeaf/WebContent/pages/phonepackage/images/foot.jpg;/orgdeaf/WebContent/pages/phonepackage/images/lr.jpg;/orgdeaf/WebContent/pages/phonepackage/manage.js;/orgdeaf/WebContent/pages/phonepackage/manage.jsp;/orgdeaf/WebContent/pages/phonepackage/phonepackage.js;/orgdeaf/WebContent/pages/phonepackage/phonepackage.jsp;/orgdeaf/WebContent/pages/weather.jsp;/orgdeaf/WebContent/resource/front/lr/css/header.css;/orgdeaf/WebContent/resource/front/lr/images/lr.jpg;/orgdeaf/WebContent/resource/js/LG.js;/orgdeaf/src/com/engc/newwmb/fileupload/FileUploadManager.java;/orgdeaf/src/com/engc/newwmb/utils/ZipTool.java;/orgdeaf/src/com/engc/phonepackage;/orgdeaf/src/com/engc/phonepackage/web;/orgdeaf/src/com/engc/phonepackage/web/PhonePackage.java;/orgdeaf/src/com/engc/phonepackage/web/PhonePackageManage.java;/orgdeaf/src/config/sql/phonepackage.xml;/orgdeaf/src/springconfig/applicationContext-mvc.xml;/orgdeaf/src/config/Global.properties;/orgdeaf/WebContent/pages/front/navi.jsp;/orgdeaf/src/com/engc/phonepackage/web/PhonePackage.java;/orgdeaf/WebContent/pages/act/actApply/actApply.js;/orgdeaf/WebContent/pages/front/index.jsp;/orgdeaf/WebContent/pages/personal/personAll.jsp;/orgdeaf/WebContent/pages/personal/personAlls.jsp;/orgdeaf/WebContent/pages/personal/personIndex1.jsp;/orgdeaf/WebContent/pages/register/regStep.js;/orgdeaf/WebContent/pages/register/regStep.jsp;/orgdeaf/WebContent/pages/teammanagement/teamInformationManagement/selectTeamAdmin.jsp;/orgdeaf/WebContent/pages/teammanagement/teamInformationManagement/teamInformationManagement.js;/orgdeaf/WebContent/resource/front/lr/css/eduit.css;/orgdeaf/src/com/engc/index/web/Index.java;/orgdeaf/src/com/engc/newwmb/fileupload/UploadJson.java;/orgdeaf/src/com/engc/personal/web/PersonalController.java;/orgdeaf/src/com/engc/personal/web/PersonalListController.java;/orgdeaf/src/com/engc/register/web/RegisterController.java;/orgdeaf/src/com/engc/teammangemnet/web/MemberMaintain.java;/orgdeaf/src/com/engc/teammangemnet/web/TeamInformationManagement.java;/orgdeaf/src/config/sql/newWmbSql.xml;";

        String[] logs = StringUtils.split(changeLog, ";");

        List<String> changes = new ArrayList<String>();

        for (String log : logs)
        {
            changes.add(log);
        }

        for (String change : changes)
        {

            if (change.endsWith("java"))
            {
                change = StringUtils.replaceOnce(change, ".java", ".class");
                change = StringUtils.replaceOnce(change, "/src/", "/build/classes/");
            }
            File file = new File(root + change);

            if (file.isDirectory())
            {
                continue;
            }
            
            System.out.println(change);

            FileInputStream fileInputStream = new FileInputStream(file);

            File dstFile = new File(dest + change);

            String dic = dstFile.getParent();

            if (!new File(dic).exists())
            {
                new File(dic).mkdirs();
            }

            FileOutputStream fileOutputStream = new FileOutputStream(dstFile);

            FileChannel readChannel = fileInputStream.getChannel();
            FileChannel writeChannel = fileOutputStream.getChannel();

            readChannel.transferTo(0, readChannel.size(), writeChannel);

            readChannel.close();
            writeChannel.close();

        }

    }
}
